package Menus;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;

import AI.AiEntity;
import AI.Person;
import AI.Crew.Crew;
import AI.Enemy.Enemy;
import Events.CrewArrival;
import Events.Event;
import FrameWork.Menu;
import Main.SpaceGame;

public class ViewMenu extends Menu
{
	int pixXPos = SpaceGame.windowXSize-200;
	int pixYPos = 100;
	int width = 200;
	int height = SpaceGame.windowYSize-100;
	int level = 1;
	public int currentEntity;
	boolean cursorRequirement = true;
	private SpaceGame main;
	private ArrayList<AiEntity> entitiesAtCursor = new ArrayList<AiEntity>();

	public ViewMenu(SpaceGame main)
	{
		this.main = main;
		currentEntity = 0;
	}
	@Override
	public void draw(Graphics g) 
	{
		g.translate(pixXPos, pixYPos);
		
		g.setColor(Color.LIGHT_GRAY);
		g.fillRect(0, 0, width, height);
		g.setColor(Color.DARK_GRAY);
		g.fillRect(5, 5, width-10, height-10);
		
		List<String> lines = new ArrayList<String>();
		List<Color>  colors= new ArrayList<Color>();
		
		if(entitiesAtCursor.size() > 0)
		{
			AiEntity entity = entitiesAtCursor.get(currentEntity);
			if(entity instanceof Enemy)
				colors.add(Color.red);
			else if(entity instanceof Crew)
				colors.add(Color.green);
			else
				colors.add(Color.yellow);
			
			if (entity instanceof Crew)
				lines.add(entity.getClass().getSimpleName() +" " + ((Person) entity).getName());
			else
				lines.add(entity.getClass()+"");
			
			colors.add(Color.BLACK);
			lines.add("");
			
			colors.add(Color.cyan);
			lines.add("Health - " + (int)(entity.health+.5) + " %");
			
			if(entitiesAtCursor.size() > 1)
			{
				colors.add(Color.black);
				lines.add("");
				
				colors.add(Color.cyan);
				lines.add("n - Next Entity");
			}
			
			printLines(g, lines, colors);
		}
		
		g.translate(-pixXPos, -pixYPos);
	}

	@Override
	public boolean requiresCursor() 
	{
		return cursorRequirement;
	}

	@Override
	public void setRequiresCursor(boolean f) 
	{
		cursorRequirement = f;
	}

	@Override
	public int getLevel() 
	{
		return level;
	}
	
	public void update()
	{
		entitiesAtCursor.clear();
		for(AiEntity e:main.aiManager.entityList)
		{
			if(e.getX() == main.cursor.getX() && e.getY() == main.cursor.getY())
				entitiesAtCursor.add(e);
		}
		if(currentEntity >= entitiesAtCursor.size())
			currentEntity = 0;
	}
}
